package com.niit.az;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;

public class BannerPicture extends AppCompatActivity {

    private Banner mbanner;
    private Button btn_evaluation;
    private MyImageLoader myImageLoader;
    private ArrayList<Integer> imagePath;
    private ArrayList<String> imageTitle;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_picture);

        btn_evaluation = findViewById(R.id.btn_evaluation);
        textView =findViewById(R.id.textView);
        initData();
        initView();

        btn_evaluation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent myIntent=new Intent(BannerPicture.this,EvaluationIn.class);
                startActivity(myIntent);
            }
        });
    }

    private void initData() {
        imagePath =new ArrayList<>();
        imageTitle =new ArrayList<>();
        imagePath.add(R.drawable.banner01);
        imagePath.add(R.drawable.banner02);
        imagePath.add(R.drawable.banner03);
        imageTitle.add("幽夜鹿灵");
        imageTitle.add("动漫人生");
        imageTitle.add("灿烂阳光");

    }

    private void initView(){
        myImageLoader =new MyImageLoader();
        mbanner =findViewById(R.id.banner);
        //设置banner样式
        mbanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE);
        //设置图片加载器
        mbanner.setImageLoader(myImageLoader);
        //设置轮播的动画效果
        mbanner.setBannerAnimation(Transformer.ZoomOutSlide);
        //设置图片的文字
        mbanner.setBannerTitles(imageTitle);
        //设置轮播的时间间隔
        mbanner.setDelayTime(3000);
        //设置是否为自动轮播
        mbanner.isAutoPlay(true);
        //设置指示器的位置，小点点，居中显示
        mbanner.setIndicatorGravity(BannerConfig.CENTER);
        //设置图片加载地址
        mbanner.setImages(imagePath);
        //轮播图的监听
        mbanner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                switch (position){
                    case 0:
                        textView.setText("您选择了“幽夜鹿灵”！");
                        break;
                    case 1:
                        textView.setText("您选择了“动漫人生”！");
                        break;
                    case 2:
                        textView.setText("您选择了“灿烂阳光”！");
                        break;

                }
            }
        }).start();
    }


    public class MyImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context.getApplicationContext())
                    .load(path)
                    .into(imageView);
        }
    }
}